package com.aos.erp.schools.rest.division;


import com.aos.erp.common.GlobalConstant;
import com.aos.erp.common.bean.IPageBean;
import com.aos.erp.common.bean.PageBean;
import com.aos.erp.common.bean.ResultEntity;
import com.aos.erp.common.exception.BizException;
import com.aos.erp.schools.model.division.ro.AddDivisionRo;
import com.aos.erp.schools.model.division.ro.InfoDivisionRo;
import com.aos.erp.schools.model.division.ro.QueryDivisionRo;
import com.aos.erp.schools.model.division.ro.UpdateDivisionRo;
import com.aos.erp.schools.model.division.vo.ShowDivisionVo;
import com.aos.erp.schools.service.division.DivisionService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 省市对应分所 前端控制器
 * </p>
 *
 * @author chb
 * @since 2018-10-31
 */
@Slf4j
@RestController
@RequestMapping("/api/division")
@Api(value="车管所接口",tags={"车管所管理"})
public class DivisionController {
	@Autowired
	private DivisionService divisionService;


	@ApiOperation(value = "查询所有车管所", notes = "查询所有车管所")
	@GetMapping("/list")
	public ResultEntity<IPageBean<ShowDivisionVo>> listTemplate(QueryDivisionRo queryDivisionRo) {
		return ResultEntity.success(divisionService.findByPage(queryDivisionRo));
	}


	@ApiOperation(value = "新增车管所", notes = "新增车管所")
	@RequestMapping(value = "/add",method = RequestMethod.POST)
	public ResultEntity addDivision(@RequestBody List<AddDivisionRo> addDivisionRoList,String currentUserId) throws  Exception{
		divisionService.addBean(addDivisionRoList,currentUserId);
		return ResultEntity.success();
	}

	@ApiOperation(value = "删除车管所", notes = "删除车管所")
	@RequestMapping(value = "/delete",method = RequestMethod.POST)
	@ApiImplicitParam(name = "id",value = "主键",required = true,dataType ="String",paramType ="query" )
	public ResultEntity deleteDivision(@RequestParam String id){
		if(id==null){
			return ResultEntity.failed("参数不能为空");
		}
		return divisionService.deleteDivision(id);
	}

	/**
	 * 获取该市下面的车管所
	 * @[param cityId  城市id
	 * @return
	 */
	@ApiOperation(value = "获取该市下面的车管所", notes = "获取该市下面的车管所")
	@RequestMapping(value = "/info", method = RequestMethod.POST)
	@ApiImplicitParam(name = "cityId",value = "城市id",required = true,dataType ="long",paramType ="query" )
	public ResultEntity<List<InfoDivisionRo>> divisionInfo(Long cityId){
		return ResultEntity.success(divisionService.divisionInfo(cityId));
	}

	/**
	 * 获取该市下面的车管所（忽略）
	 * @[param cityId  城市id
	 * @return
	 */
	@ApiOperation(value = "获取该市下面的车管所（忽略）", notes = "获取该市下面的车管所（忽略）")
	@RequestMapping(value = GlobalConstant.GATEWAY_IGNORE+"/info", method = RequestMethod.POST)
	@ApiImplicitParam(name = "cityId",value = "城市id",required = true,dataType ="long",paramType ="query" )
	public ResultEntity<List<InfoDivisionRo>> divisionInfoHl(Long cityId){
		return ResultEntity.success(divisionService.divisionInfo(cityId));
	}



	/**
	 * 修改车管所
	 * @[param UpdateDivisionRos  车管所实体
	 * @return
	 */
	@ApiOperation(value = "修改车管所", notes = "修改车管所")
	@RequestMapping(value = "/update",method = RequestMethod.POST)
	public ResultEntity updateDivision(@RequestBody  List<UpdateDivisionRo> UpdateDivisionRo) throws BizException {
		return divisionService.updateDivision(UpdateDivisionRo);
	}


}

